package collatz;


public class CollatzCalculator{
	public static final int numberOfRepetitions = 100;

	private static long[] generateNumbers(int first, int last){
		long numbers[] = new long[last+1-first];

		for(int i = 0 ; i < numbers.length; i++)
			numbers[i] = first+1;

		return numbers;
	}

	public static void main(String args[]){

		long grainsize = Integer.parseInt(args[0]);
		int threadssize = Integer.parseInt(args[1]);
		
		//		
		//		//ResultsRegister register = new ResultsRegister(System.out);
		CollatzExecutions CE = new CollatzExecutions(grainsize, threadssize);
		//System.out.println("Teste");
		//		
		long numbers[] = generateNumbers(1,(int)grainsize);
		//		
		executeExperiment(CE,numbers);

	}

	private static void executeExperiment(CollatzExecutions c, long[] numbers){

		long total = 0;
		
		for(int i = 0 ; i < numberOfRepetitions; i++){
			long time = System.nanoTime();
			c.calculate(numbers);
			while(c.isAlive());
			total += (System.nanoTime() - time);
		}
		
		System.out.println("Media = "+String.valueOf(total/numberOfRepetitions));
		
	}



}
